package com.isoftstone.disk.spring.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class BaseController {
    @Resource
    private MessageSource messageSource;
    protected String jsonSuccess(String i18nKey,Object ... objects){
        Locale locale = LocaleContextHolder.getLocale();
        String message =  messageSource.getMessage(i18nKey,objects,locale);
        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        map.put("msg",message);
        map.put("description",message);
        return JSON.toJSONString(map);
    }
}
